package cn.wolfcode.wolf2world.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * @author 杨兴健
 * @Date 2020/8/7 20:50
 */
@Setter
@Getter
public class JsonResult<T> {
    public static final int CODE_SUCCESS = 200;
    public static final String MSG_SUCCESS = "操作成功";

    public static final int CODE_NOLOGIN = 401;
    public static final String MSG_NOLOGIN = "请先登录";

    public static final int CODE_ERROR = 500;
    public static final String MSG_ERROR = "系统异常，请联系管理员";

    public static final int CODE_ERROR_PARAM = 501;
    public static final String MSG_ERROR_PARAM = "参数异常，请联系管理员";

    private int code;
    private String msg;
    private T data;

    public JsonResult() {}

    public JsonResult(Integer code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static <T> JsonResult success(T data) {
        return new JsonResult(CODE_SUCCESS,MSG_SUCCESS,data);
    }
    public static JsonResult success() {
        return new JsonResult(CODE_SUCCESS,MSG_SUCCESS,null);
    }
    public static JsonResult error(Integer code,String msg) {
        return new JsonResult(code,msg,null);
    }
    public static JsonResult defaultError() {
        return new JsonResult(CODE_ERROR,MSG_ERROR,null);
    }
    public static  JsonResult fail() {
        return new JsonResult(CODE_ERROR_PARAM,MSG_ERROR_PARAM,null);
    }
    public static  JsonResult noLogin() {
        return new JsonResult(CODE_NOLOGIN,MSG_NOLOGIN,null);
    }

}
